import com.tsj.message.Consumer;
import com.tsj.message.config.KafkaProperties;
import org.apache.kafka.common.errors.TimeoutException;

import java.util.Optional;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

public class ConsumerStarter {

    public static void main(String[] args) throws InterruptedException {
        CountDownLatch latch = new CountDownLatch(1);
        Consumer consumerThread = new Consumer(KafkaProperties.TOPIC, "DemoConsumer", Optional.empty(), false, 100, latch);
        consumerThread.start();

        if (!latch.await(60, TimeUnit.SECONDS)) {
            throw new TimeoutException("Timeout after 30 seconds waiting for demo consumer to finish");
        }
        consumerThread.shutdown(30, TimeUnit.SECONDS);
        System.out.println("demo consumer to finish!");
    }
}
